package com.company.cloud.web.controller;


import com.company.cloud.web.service.WebArtService;
import com.company.cloud.web.service.WebIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private WebIndexService webIndexService;

    @Autowired
    private WebArtService webArtService;

    /**
     * 列表
     *
     * @param model
     * @return
     */
    @RequestMapping("/list")
    public String query(Model model, @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {
        Map<String, Object> indexMap = webIndexService.getPageIndexData();
        model.addAttribute("category", indexMap.get("category"));
        Map<String, Object> menusMap = webArtService.staticPageTree("top");
        model.addAttribute("menu", menusMap);
        model.addAttribute("i18n", i18n);

        Map<String, Object> footer = webArtService.staticPageTree("bottom");
        model.addAttribute("footer", footer);
        model.addAttribute("friendLink", indexMap.get("friendLink"));
        model.addAttribute("copyright", indexMap.get("copyright"));
        return "user/list";
    }

    /**
     * 设置
     *
     * @param model
     * @return
     */
    @RequestMapping("/setting")
    public String setting(Model model, @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {
        Map<String, Object> indexMap = webIndexService.getPageIndexData();
        model.addAttribute("category", indexMap.get("category"));
        Map<String, Object> menusMap = webArtService.staticPageTree("top");
        model.addAttribute("menu", menusMap);
        model.addAttribute("i18n", i18n);

        Map<String, Object> footer = webArtService.staticPageTree("bottom");
        model.addAttribute("footer", footer);
        model.addAttribute("friendLink", indexMap.get("friendLink"));
        model.addAttribute("copyright", indexMap.get("copyright"));
        return "user/setting";
    }

    /**
     * 地址
     *
     * @param model
     * @return
     */
    @RequestMapping("/address")
    public String address(Model model, @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {
        Map<String, Object> indexMap = webIndexService.getPageIndexData();
        model.addAttribute("category", indexMap.get("category"));
        Map<String, Object> menusMap = webArtService.staticPageTree("top");
        model.addAttribute("menu", menusMap);
        model.addAttribute("i18n", i18n);

        Map<String, Object> footer = webArtService.staticPageTree("bottom");
        model.addAttribute("footer", footer);
        model.addAttribute("friendLink", indexMap.get("friendLink"));
        model.addAttribute("copyright", indexMap.get("copyright"));
        return "user/address";
    }

    /**
     * 地址设置
     *
     * @param model
     * @return
     */
    @RequestMapping("/addressDetail")
    public String addressDetail(Model model, @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {
        Map<String, Object> indexMap = webIndexService.getPageIndexData();
        model.addAttribute("category", indexMap.get("category"));
        Map<String, Object> menusMap = webArtService.staticPageTree("top");
        model.addAttribute("menu", menusMap);
        model.addAttribute("i18n", i18n);

        Map<String, Object> footer = webArtService.staticPageTree("bottom");
        model.addAttribute("footer", footer);
        model.addAttribute("friendLink", indexMap.get("friendLink"));
        model.addAttribute("copyright", indexMap.get("copyright"));
        return "user/addressDetail";
    }

    /**
     * 订单
     *
     * @param model
     * @return
     */
    @RequestMapping("/order")
    public String order(Model model, @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {
        Map<String, Object> indexMap = webIndexService.getPageIndexData();
        model.addAttribute("category", indexMap.get("category"));
        Map<String, Object> menusMap = webArtService.staticPageTree("top");
        model.addAttribute("menu", menusMap);
        model.addAttribute("i18n", i18n);

        Map<String, Object> footer = webArtService.staticPageTree("bottom");
        model.addAttribute("footer", footer);
        model.addAttribute("friendLink", indexMap.get("friendLink"));
        model.addAttribute("copyright", indexMap.get("copyright"));
        return "user/order";
    }

    /**
     * 详单详情
     *
     * @param model
     * @return
     */
    @RequestMapping("/orderDetail")
    public String orderDetail(Model model, @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {
        Map<String, Object> indexMap = webIndexService.getPageIndexData();
        model.addAttribute("category", indexMap.get("category"));
        Map<String, Object> menusMap = webArtService.staticPageTree("top");
        model.addAttribute("menu", menusMap);
        model.addAttribute("i18n", i18n);

        Map<String, Object> footer = webArtService.staticPageTree("bottom");
        model.addAttribute("footer", footer);
        model.addAttribute("friendLink", indexMap.get("friendLink"));
        model.addAttribute("copyright", indexMap.get("copyright"));
        return "user/orderDetail";
    }


    /**
     * 足迹
     *
     * @param model
     * @return
     */
    @RequestMapping("/history")
    public String history(Model model, @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {
        Map<String, Object> indexMap = webIndexService.getPageIndexData();
        model.addAttribute("category", indexMap.get("category"));
        Map<String, Object> menusMap = webArtService.staticPageTree("top");
        model.addAttribute("menu", menusMap);
        model.addAttribute("i18n", i18n);

        Map<String, Object> footer = webArtService.staticPageTree("bottom");
        model.addAttribute("footer", footer);
        model.addAttribute("friendLink", indexMap.get("friendLink"));
        model.addAttribute("copyright", indexMap.get("copyright"));
        return "user/history";
    }

    /**
     * cart
     *
     * @param model
     * @return
     */
    @RequestMapping("/cart")
    public String cart(Model model, @CookieValue(value = "org.springframework.web.servlet.i18n.CookieLocaleResolver.LOCALE", defaultValue = "zh-CN") String i18n) {

        Map<String, Object> indexMap = webIndexService.getPageIndexData();
        model.addAttribute("category", indexMap.get("category"));
        Map<String, Object> menusMap = webArtService.staticPageTree("top");
        model.addAttribute("menu", menusMap);
        model.addAttribute("i18n", i18n);

        Map<String, Object> footer = webArtService.staticPageTree("bottom");
        model.addAttribute("footer", footer);
        model.addAttribute("friendLink", indexMap.get("friendLink"));
        model.addAttribute("copyright", indexMap.get("copyright"));
        return "user/cart";
    }


}
